home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1410_setCellClass_initialization.rtf < prev    next >
Text File  |  1993-11-08  |  1KB  |  56 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f2\fmodern Courier;\f1\fmodern Ohlfs;}
  2. \paperw13040
  3. \paperh10800
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;\red84\green84\blue84;\red83\green83\blue83;\red82\green82\blue82;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q:  I have subclassed Button and ButtonCell in my application.  I am setting the cell class for my button in the 
  8. \b -init:
  9. \b0  method for my Button subclass like this:\
  10. \
  11.  
  12. \f2\fs24\fc1\cf1     @implementation MyButton : Button\
  13. \
  14.     -init\
  15.     \{\
  16.         [super init];\
  17.  
  18. \b         [MyButton  setCellClass: [MyButtonCell class]];\
  19.  
  20. \b0         return self;\
  21.     \}\
  22.     @end\
  23.  
  24. \f0\fs28\fc0\cf0 \
  25. However my cell class is not being created and initialized properly.  What is going on?\
  26. \
  27. A:  
  28. \b setCellClass:
  29. \b0  is a factory method and must occur prior to any instance creation—
  30. \b init:
  31. \b0  is too late.  The correct place to do this is in the 
  32. \b +initialize
  33. \b0  factory method for your Button subclass (which is called before any instances are created).  This problem can occur with all Cell subclasses—such as TextField and NXBrowser.   (
  34. \b +initialize
  35. \b0  is an Object factory method; see the Object class specification sheet for more information.) \
  36. \
  37.  
  38. \f2\fs24\fc1\cf1     @implementation MyButton : Button\
  39. \
  40.     +initialize\
  41.     \{\
  42.         [super initialize];\
  43.  
  44. \b         [MyButton  setCellClass: [MyButtonCell class]];\
  45.  
  46. \b0         return self;\
  47.     \}\
  48.     @end\
  49.  
  50. \f0\fs28 \
  51. QA761\
  52. \
  53. Valid for 2.0, 3.0\
  54. \
  55.  
  56.